package com.atguigu.study.bootredis.leetcode;

/**
 * @author jiangta
 * @version 1.0
 * @date 2020/12/15 5:48 下午
 */
public class ReverseInteger {

    public static int reverse(int x) {
        String xstr = String.valueOf(x);
        int i = 0;
        int j = xstr.length() - 1;
        if ('-' ==xstr.charAt(0)) {
            i = 1;
        }
        if (i == j) {
            return x;
        }
        char[] chars = xstr.toCharArray();
        while (i < j) {
            char temp = chars[i];
            chars[i] = chars[j];
            chars[j] = temp;
            i++;
            j--;
        }
        StringBuilder retStr = new StringBuilder();
        for (char xx : chars) {
            retStr.append(xx);
        }
        return Integer.parseInt(retStr.toString());
    }

    public static void main(String[] args) {
        //System.out.println(reverse(123));
        System.out.println(reverse(-123));
    }
}
